package com.designpatterns.flyweightpattern;

import java.util.HashMap;

import com.designpatterns.flyweightpattern.impl.Circle;

public class ShapeFactory
{
	private static final HashMap<String, Shape> circleMap = new HashMap<>();

	public static Shape getCircle(String color)
	{
		// 如果对象已经被创建，则直接返回
		Circle circle = (Circle) circleMap.get(color);

		// 如果HashMap没有存储该对象则新建一个
		if (circle == null)
		{
			circle = new Circle(color);
			circleMap.put(color, circle);
			System.out.println("Creating circle of color : " + color);
		}
		return circle;
	}
}
